<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/16x16.png">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic|Lato', 'Microsoft Yahei Light:300,300italic,400,400italic,700,700italic|Cambria', 'Microsoft Yahei Light:300,300italic,400,400italic,700,700italic|Verdana', Lato, 'Microsoft Yahei Light:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"right","display":"hide","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Problem 54 Poker hands In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way:  High Card: Highest value card. One Pair: Two cards of the s">
<meta property="og:type" content="article">
<meta property="og:title" content="Problem 54">
<meta property="og:url" content="http://yoursite.com/54/index.html">
<meta property="og:site_name" content="Project Euler | 欧拉计划">
<meta property="og:description" content="Problem 54 Poker hands In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way:  High Card: Highest value card. One Pair: Two cards of the s">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2003-10-11T01:00:00.000Z">
<meta property="article:modified_time" content="2015-08-10T16:18:20.000Z">
<meta property="article:author" content="sx349">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/54/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Problem 54 | Project Euler | 欧拉计划</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Project Euler | 欧拉计划</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-problem">

    <a href="/problems" rel="section"><i class="fa fa-tags fa-fw"></i>题目</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/54/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="sx349">
      <meta itemprop="description" content="Project Euler | 欧拉计划 中文翻译站">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Project Euler | 欧拉计划">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Problem 54
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">题目发布于</span>

              <time title="发布时间：2003-10-10 18:00:00" itemprop="dateCreated datePublished" datetime="2003-10-10T18:00:00-07:00">2003-10-10</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">翻译更新于</span>
                <time title="更新时间：2015-08-10 09:18:20" itemprop="dateModified" datetime="2015-08-10T09:18:20-07:00">2015-08-10</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <hr>
<h1 id="Problem-54"><a href="#Problem-54" class="headerlink" title="Problem 54"></a><a href="https://projecteuler.net/problem=54" target="_blank" rel="noopener">Problem 54</a></h1><hr>
<p><strong>Poker hands</strong></p>
<p>In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way:</p>
<ul>
<li><strong>High Card</strong>: Highest value card.</li>
<li><strong>One Pair</strong>: Two cards of the same value.</li>
<li><strong>Two Pairs</strong>: Two different pairs.</li>
<li><strong>Three of a Kind</strong>: Three cards of the same value.</li>
<li><strong>Straight</strong>: All cards are consecutive values.</li>
<li><strong>Flush</strong>: All cards of the same suit.</li>
<li><strong>Full House</strong>: Three of a kind and a pair.</li>
<li><strong>Four of a Kind</strong>: Four cards of the same value.</li>
<li><strong>Straight Flush</strong>: All cards are consecutive values of same suit.</li>
<li><strong>Royal Flush</strong>: Ten, Jack, Queen, King, Ace, in same suit.</li>
</ul>
<p>The cards are valued in the order:2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.</p>
<p>If two players have the same ranked hands then the rank made up of the highest value wins; for example, a pair of eights beats a pair of fives (see example 1 below). But if two ranks tie, for example, both players have a pair of queens, then highest cards in each hand are compared (see example 4 below); if the highest cards tie then the next highest cards are compared, and so on.</p>
<p>Consider the following five hands dealt to two players:</p>
<table>
<thead>
<tr>
<th align="center"><strong>Hand</strong></th>
<th align="center"><strong>Player 1</strong></th>
<th align="center"><strong>Player 2</strong></th>
<th align="center"><strong>Winner</strong></th>
</tr>
</thead>
<tbody><tr>
<td align="center"><strong>1</strong></td>
<td align="center">5H 5C 6S 7S KD</td>
<td align="center">2C 3S 8S 8D TD</td>
<td align="center">Player 2</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">Pair of Fives</td>
<td align="center">Pair of Eights</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center"><strong>2</strong></td>
<td align="center">5D 8C 9S JS AC</td>
<td align="center">2C 5C 7D 8S QH</td>
<td align="center">Player 1</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">Highest card Ace</td>
<td align="center">Highest card Queen</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center"><strong>3</strong></td>
<td align="center">2D 9C AS AH AC</td>
<td align="center">3D 6D 7D TD QD</td>
<td align="center">Player 2</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">Three Aces</td>
<td align="center">Flush with Diamonds</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center"><strong>4</strong></td>
<td align="center">4D 6S 9H QH QC</td>
<td align="center">3D 6D 7H QD QS</td>
<td align="center">Player 1</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">Pair of Queens</td>
<td align="center">Pair of Queens</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">Highest card Nine</td>
<td align="center">Highest card Seven</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center"><strong>5</strong></td>
<td align="center">2H 2D 4C 4D 4S</td>
<td align="center">3C 3D 3S 9S 9D</td>
<td align="center">Player 1</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">Full House</td>
<td align="center">Full House</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">with Three Fours</td>
<td align="center">with Three Threes</td>
<td align="center">&nbsp;</td>
</tr>
</tbody></table>
<p>The file, <a href="https://projecteuler.net/project/resources/p054_poker.txt" target="_blank" rel="noopener">poker.txt</a>, contains one-thousand random hands dealt to two players. Each line of the file contains ten cards (separated by a single space): the first five are Player 1’s cards and the last five are Player 2’s cards. You can assume that all hands are valid (no invalid characters or repeated cards), each player’s hand is in no specific order, and in each hand there is a clear winner.</p>
<p>How many hands does Player 1 win?</p>
<hr>
<p><strong>扑克手牌</strong></p>
<p>在扑克游戏中，玩家的手牌由五张牌组成，其等级由低到高分别为：</p>
<ul>
<li><strong>单牌</strong>：牌面最大的一张牌。</li>
<li><strong>对子</strong>：两张牌面一样的牌。</li>
<li><strong>两对</strong>：两个不同的对子。</li>
<li><strong>三条</strong>：三张牌面一样的牌。</li>
<li><strong>顺子</strong>：五张牌的牌面是连续的。</li>
<li><strong>同花</strong>：五张牌是同一花色。</li>
<li><strong>葫芦</strong>：三条带一个对子。</li>
<li><strong>四条</strong>：四张牌面一样的牌。</li>
<li><strong>同花顺</strong>：五张牌的牌面是连续的且为同一花色。</li>
<li><strong>同花大顺</strong>：同一花色的10、J、Q、K、A。</li>
</ul>
<p>牌面由小到大的顺序是：2、3、4、5、6、7、8、9、10、J、Q、K、A。</p>
<p>如果两名玩家的手牌处于同一等级，那么牌面较大的一方获胜；例如，一对8胜过一对5（参见例1）；如果牌面相同，例如双方各有一对Q，那么就比较玩家剩余的牌中最大的牌（参见例4）；如果最大的牌相同，则比较次大的牌，依此类推。</p>
<p>考虑以下五局游戏中双方的手牌：</p>
<table>
<thead>
<tr>
<th align="center"><strong>手牌</strong></th>
<th align="center"><strong>玩家1</strong></th>
<th align="center"><strong>玩家2</strong></th>
<th align="center"><strong>胜者</strong></th>
</tr>
</thead>
<tbody><tr>
<td align="center"><strong>1</strong></td>
<td align="center">红桃5 草花5 黑桃6 黑桃7 方片K</td>
<td align="center">草花2 黑桃3 黑桃8 方片8 方片10</td>
<td align="center">玩家2</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">一对5</td>
<td align="center">一对8</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center"><strong>2</strong></td>
<td align="center">方片5 草花8 黑桃9 黑桃J 草花A</td>
<td align="center">草花2 草花5 方片7 黑桃8 红桃Q</td>
<td align="center">玩家1</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">单牌A</td>
<td align="center">单牌Q</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center"><strong>3</strong></td>
<td align="center">方片2 草花9 黑桃A 红桃A 草花A</td>
<td align="center">方片3 方片6 方片7 方片10 方片Q</td>
<td align="center">玩家2</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">三条A</td>
<td align="center">同花方片</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center"><strong>4</strong></td>
<td align="center">方片4 黑桃6 红桃9 红桃Q 草花Q</td>
<td align="center">方片3 方片6 红桃7 方片Q 黑桃Q</td>
<td align="center">玩家1</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">一对Q</td>
<td align="center">一对Q</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">最大单牌9</td>
<td align="center">最大单牌7</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center"><strong>5</strong></td>
<td align="center">红桃2 方片2 草花4 方片4 黑桃4</td>
<td align="center">草花3 方片3 黑桃3 黑桃9 方片9</td>
<td align="center">玩家1</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">葫芦</td>
<td align="center">葫芦</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">（三条4）</td>
<td align="center">（三条3）</td>
<td align="center">&nbsp;</td>
</tr>
</tbody></table>
<p>在这个文本文件<a href="https://projecteuler.net/project/resources/p054_poker.txt" target="_blank" rel="noopener">poker.txt</a>中，包含有两名玩家一千局的手牌。每一行包含有10张牌（均用一个空格隔开）：前5张牌属于玩家1，后5张牌属于玩家2。你可以假定所有的手牌都是有效的（没有无效的字符或是重复的牌），每个玩家的手牌不一定按顺序排列，且每一局都有确定的赢家。</p>
<p>其中有多少局玩家1获胜？</p>
<hr>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/53/" rel="prev" title="Problem 53">
      <i class="fa fa-chevron-left"></i> Problem 53
    </a></div>
      <div class="post-nav-item">
    <a href="/55/" rel="next" title="Problem 55">
      Problem 55 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="gitalk-container"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Problem-54"><span class="nav-text">Problem 54</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="sx349"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">Leonhard Euler(1707-1783)</p>
  <p class="site-description motion-element">Project Euler | 欧拉计划<br>中文翻译站</p>
</div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-title">
          <a href="https://projecteuler.net/" title="https:&#x2F;&#x2F;projecteuler.net" rel="noopener" target="_blank">Project Euler</a>
        </li>
        <li class="links-of-blogroll-title">
          <a href="http://jakwings.is-programmer.com/Project_Euler" title="http:&#x2F;&#x2F;jakwings.is-programmer.com&#x2F;Project_Euler" rel="noopener" target="_blank">饮水思源汉化</a>
        </li>
        <li class="links-of-blogroll-title">
          <a href="http://sx349.github.io/" title="http:&#x2F;&#x2F;sx349.github.io" rel="noopener" target="_blank">译者博客</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2001 – 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fas fa-calculator"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Project Euler | 欧拉计划</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">

<script>
NexT.utils.loadComments(document.querySelector('#gitalk-container'), () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
	  title       : document.title.substr(0,29),
      clientID    : '4ba99a8839c5e7dde683',
      clientSecret: '3984f7cad409553d6afde8dbc2c08fc425e7bbdc',
      repo        : 'pe-cn-comments',
      owner       : 'pe-cn',
      admin       : ['sx349'],
      id          : '201f2fa0e8c04527ea53a5c4a1cc24b0',
        language: '',
      distractionFreeMode: true
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
});
</script>

</body>
</html>
